package net.sxnic.workflow.pd.dao;

import java.util.List;

import net.sxinfo.core.spring25.HibernateDao;
import net.sxnic.workflow.pd.Pd;

import org.springframework.stereotype.Repository;

@Repository("pdDao")
public class HibernatePdDao extends HibernateDao<Pd, String> implements PdDao {

	@Override
	public Pd findLatestPdByName(String name) {
		List<Pd> list = find("from Pd where name='" + name
				+ "' order by creationDate desc, pdVersion desc");
		if (list == null || list.size()==0) {
			return null;
		} else {
			return list.get(0);
		}

	}

	@Override
	public Pd findByNameVerision(String name, int version) {
		List<Pd> list = find("from Pd where name=? and pdVersion=? ",
				new Object[] { name, version });
		if (list == null) {
			return null;
		} else {
			return list.get(0);
		}
	}

}
